package com.yangff.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class LogAspect {

    @Around("@annotation(com.yangff.anno.LogExecuteTime) || @within(com.yangff.anno.LogExecuteTime)")
    public Object logExecuteTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();

        Object object = joinPoint.proceed();

        long end = System.currentTimeMillis();
        log.debug("函数{} 运行时间为 {} ms",joinPoint.getSignature().getName(),end - start);
        return object;
    }
}
